package copy.bean;

import java.util.HashMap;
import java.util.Map;

public class Easy {
    private static Map<Class,Class> implClassMap = new HashMap<>();
    private static Map<Class,Object> beanMap = new HashMap<>();

    public void authorInfo(){
        String name = "李滋芸";
        String WeiXin = "公众号: 小豆的奇思妙想";
        String Email ="1843180846@qq.com";
        String note = "笔记网站:liziyun.work:10086";
    }
    /**
     * 李滋芸
     * 邮箱: 1843180846@qq.com
     * 微信公众号: 小豆的奇思妙想
     * 笔记网站: liziyun.work:10086
     * @param cls
     * @param <T>
     * @return
     */
    public static <T> T  bean(Class<T> cls){

        Class implClass = implClassMap.get(cls);
        if (implClass == null){
            try {
                implClass = Class.forName(cls.getName()+"$"+cls.getSimpleName()+"Impl");
                implClassMap.put(cls,implClass);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }

        if (beanMap.get(implClass) == null){
            try {
                beanMap.put(implClass,implClass.newInstance());
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return (T)beanMap.get(implClass);
    }
}
